import 'package:flutter/foundation.dart';
import 'package:syria_sports/core/app_export.dart';
import 'package:flutter/material.dart';
import 'package:syria_sports/core/utils/show_toast.dart';
import 'package:syria_sports/data/apiClient/apis_data.dart';
import 'package:syria_sports/data/models/auth/user.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:syria_sports/presentation/players/add_player_page/bloc/add_player_page_screen.dart';
import 'package:syria_sports/presentation/players/add_player_page/widgets/my_circle_avatar.dart';
import 'package:syria_sports/presentation/admin_home_tabs/cp_tab/bloc/cp_cubit.dart';
import '../../../../data/controllers/users_controller.dart';
import '../../../../dialogs/add_attendance_dialog.dart';
import '../../../../dialogs/delete_player_confirmation.dart';
import '../../../dialogs/subscription_dialog.dart';
import '../../players/player_profile_screen/player_profile_screen.dart';


class PlayerItemView extends StatelessWidget {
  final User user;
  const PlayerItemView({super.key, required this.user});

  @override
  Widget build(BuildContext context) {

    return GestureDetector(
      onTap: () {
        showDialog(
          context: context,
          builder: (BuildContext context) {
            return SubscriptionDialog(user: user,);
          },
        );
        /*Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => PlayerProfileScreen.builder(
              context: context,
              user: user,
            ),
          ),
        );*/
      },
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          children: [
            MyCircleAvatar(
              borderColor: Colors.red,
              backgroundColor:Theme.of(context).colorScheme.onPrimaryContainer,
              editMode: false,
              width: 32,
              imageURL: user.image,
            ),
            SizedBox(height: 4),
            Text(user.fullName, style: theme.textTheme.titleSmall,textAlign: TextAlign.center,),// مسافة أفقية بين العناصر
          ],
        ),
      ),
    );
  }
  void showDeleteConfirmation(BuildContext context, User player) {
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return DeleteConfirmationDialog(
          playerName: player.fullName,
          titleUser: 'اللاعب',
          onConfirm: () {
            UsersController.deleteById(player.userId??'-1');
            if (kDebugMode) {
              print('تم حذف اللاعب ${player.fullName}!');
            }
          },
        );
      },
    );
  }

  void showAddAttendanceDialog(BuildContext context, User player) {
    if(APISData.cpCubit.state is CPLoading){
      showErrorMessage(message: 'يرجى الانتظار ريثما يتم جلب التمارين والنوادي');
      return;
    }
    showDialog(
      context: context,
      builder: (BuildContext context) {
        return AddAttendanceDialog(
          player: player,
        );
      },
    );

  }
}

